#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
double a[N];
struct Node {
  double s, s2;
  double tag;
} tr[N << 2];
#define s(p) tr[p].s
#define s2(p) tr[p].s2
#define tag(p) tr[p].tag

void pushup(int p) {
  s(p) = s(p << 1) + s(p << 1 | 1);
  s2(p) = s2(p << 1) + s2(p << 1 | 1);
}
void build(int p, int l, int r) {
  tag(p) = 0.0;
  if (l == r) {
    s(p) = a[l];
    s2(p) = a[l] * a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void addtag(double k, int p, int l, int r) {
  tag(p) += k;
  s2(p) += 2 * k * s(p) + (r + 1 - l) * k * k;
  s(p) += (r + 1 - l) * k;
}
void pushdown(int p, int l, int r) {
  if (tag(p)) {
    int mid = (l + r) >> 1;
    addtag(tag(p), p << 1, l, mid);
    addtag(tag(p), p << 1 | 1, mid + 1, r);
    tag(p) = 0.0;
  }
}
void update(int L, int R, double k, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(k, p, l, r);
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, k, p << 1, l, mid);
  if (R > mid) update(L, R, k, p << 1 | 1, mid + 1, r);
  pushup(p);
}
double query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return s(p);
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  double res = 0;
  if (L <= mid) res += query(L, R, p << 1, l, mid);
  if (R > mid) res += query(L, R, p << 1 | 1, mid + 1, r);
  return res;
}
double query2(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return s2(p);
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  double res = 0.0;
  if (L <= mid) res += query2(L, R, p << 1, l, mid);
  if (R > mid) res += query2(L, R, p << 1 | 1, mid + 1, r);
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int op, x, y;
    double k;
    cin >> op >> x >> y;
    if (op == 1) cin >> k;
    if (op == 1)
      update(x, y, k, 1, 1, n);
    else {
      int len = y + 1 - x;
      double ex = query(x, y, 1, 1, n) / len;
      double ex2 = query2(x, y, 1, 1, n) / len;
      double dx = ex2 - ex * ex;
      if (op == 2)
        cout << fixed << setprecision(4) << ex << endl;
      else
        cout << fixed << setprecision(4) << dx << endl;
    }
  }
  return 0;
}